package com.jiankangjin.appspos.services.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.jiankangjin.appspos.services.CheckServices;
import com.jiankangjin.appspos.util.ResourceMap;
import com.jiankangjin.appspos.vo.CheckVersionVo;
import com.jiankangjin.httpclient.HttpClient;

@Service
public class VersionServicesImpl implements CheckServices{
	private static final transient Log logger = LogFactory.getLog(VersionServicesImpl.class);
	
	/**
	 * 软件版本检查
	 */
	@Override
	public CheckVersionVo checkVersion(String terminalType, String terminalVer, String terminalId) {
		CheckVersionVo checkVersionVo = new CheckVersionVo();
		try {
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("terminalType", terminalType);
			params.put("terminalVersion", terminalVer);
			params.put("terminalId", terminalId);
			if (logger.isInfoEnabled()) {
				logger.info("调帐户系统检测版本:" + params);
			}
			Map<String, Object> map = HttpClient.getInstance().doPOSTgetHashMap("/accmanage/check_ter_version", params);
			if (logger.isInfoEnabled()) {
				logger.info("帐户系统检测版本返回:"+map);
			}
			if(map == null) {
				checkVersionVo.setResp_status("9999");
				checkVersionVo.setMsg("帐户系统检测版本返回空");
				return checkVersionVo;
			}
			String[] resTip = ResourceMap.getArray("A_check_ter_version_" + (String) map.get("status"));
			checkVersionVo.setResp_status(resTip[0]);
			checkVersionVo.setMsg(resTip[1]);
			checkVersionVo.setLast_version((String) map.get("latestVersion"));
			checkVersionVo.setUpdate_url((String) map.get("downloadUrl"));
			checkVersionVo.setSign("appSPOS_sign");
			return checkVersionVo;
		} catch (Exception e) {
			logger.error(this, e);
			return checkVersionVo;
		}
	}
}
